package com.dev.base.ability;


import com.dev.base.able.IBaseView;
import com.dev.base.able.IBaseViewModel;
import com.dev.base.adapter.NewsListAdapter;
import com.dev.base.bean.BaseBean;
import com.dev.base.expand.mvvm.BaseMVVMSlice;
import com.dev.base.utils.SkipUtils;
import dev.base.ResourceTable;
import ohos.aafwk.abilityjet.databinding.DataBinding;
import ohos.aafwk.content.Intent;
import ohos.agp.components.ListContainer;
import ohos.agp.components.TableLayout;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

import java.util.List;

public class MVVMAbilitySlice extends BaseMVVMSlice<MainViewModel, DataBinding> implements IBaseView, IBaseViewModel {

    private MainViewModel viewModel;
    private ListContainer selectorListContainer;
    private List<MainBean> mainBeanList;
    private NewsListAdapter newsListAdapter;

    @Override
    protected void onStart(Intent intent) {
        setiBaseView(this);
        super.onStart(intent);
        selectorListContainer = (ListContainer) findComponentById(ResourceTable.Id_content_container);
        selectorListContainer.setItemClickedListener((listContainer, component, i, l) -> {
            SkipUtils.startActivity(new WebContentSlice());
        });
        viewModel = new MainViewModel(getContext());
        viewModel.setiBaseViewModel(this);
        viewModel.login();

    }

    @Override
    protected MainViewModel getViewModel() {
        return viewModel;
    }

    @Override
    public int getLayout() {
        return ResourceTable.Layout_base_ability_slice_main;
    }

    @Override
    protected void onInactive() {
        super.onInactive();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public DataBinding todo(DataBinding dataBinding) {
        return dataBinding;
    }

    @Override
    protected void onBackground() {
        viewModel.cleaner();
        super.onBackground();
    }

    @Override
    public Context getAbilitySliceContext() {
        return getContext();
    }

    @Override
    public void getData(BaseBean bean) {

        if(ifIsThisSlice){
            mainBeanList = (List<MainBean>) bean.getDataObject();
            newsListAdapter = new NewsListAdapter(mainBeanList, this);
            selectorListContainer.setItemProvider(newsListAdapter);
//            setUIContent(ResourceTable.Layout_layout_nofound);
        }
    }
}
